class Http{
    constructor($state,$http,$q,constant,ajaxError,responseService){
        Object.assign(this,{$state,$http,$q,constant,ajaxError,responseService});
    }

    /**
     * Post
     * @param api api路径，如：api/get_winning_num。不以“/”开头。
     * @param param json对象的参数
     * @returns {Promise.<T>|*}
     */
    post(api,param,config){
        let self = this;
        let uri = self.constant.urlPrefix + api;
        let config1 = config || {};
        return self.$http.post(uri,param,config1).then(_success).catch(_error);
        function _success(response) {
            let data = response.data;
            if(response.status ===200){
                if(data.message && data.message.code==400){
                    self.$state.go("login");
                }
                return data;
            }
            return self.$q.reject(response);
        }
        function _error(response) {
            let message = response.data.message;
            return self.ajaxError.catcher(message);
        }
    }

}
Http.$inject = ["$state","$http","$q","Constant","AjaxErrorHandler","ResponseService"];
export default  Http;